Conditions | 12 |
Total Lines | 63 |
Code Lines | 60 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
Complex classes like GamePage.render often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
1 | import React, { Component } from "react" |
||
52 | |||
53 | render() { |
||
54 | if (this.state.loading === false && this.state.data) { |
||
55 | const { general, substitutes, lineup, events } = this.state.data |
||
56 | const homeTeamId = general.homeClub.id |
||
57 | const awayTeamId = general.awayClub.id |
||
58 | const ogImage = { |
||
59 | src: general?.homeClub.logo, |
||
60 | width: 180, |
||
61 | height: 180, |
||
62 | } |
||
63 | |||
64 | return ( |
||
65 | <Layout> |
||
66 | <SEO |
||
67 | lang="nl-BE" |
||
68 | title={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
69 | description={`Matchverslag ${general?.homeClub?.name} - ${general?.awayClub?.name}`} |
||
70 | path={`/game/${general?.id}`} |
||
71 | image={ogImage} |
||
72 | /> |
||
73 | <section className="grid-container site-content"> |
||
74 | <div className="grid-x grid-margin-x"> |
||
75 | <div className={"cell large-12 center"}> |
||
76 | {general.date} |
||
77 | <br /> |
||
78 | {general.status} |
||
79 | <br /> |
||
80 | {general.homeClub.name} |
||
81 | <img src={general.homeClub.logo} alt={general.homeClub.name} /> |
||
82 | {general.goalsHomeTeam} - {general.goalsAwayTeam} |
||
83 | {general.awayClub.name} |
||
84 | <img src={general.awayClub.logo} alt={general.awayClub.name} /> |
||
85 | <br /> |
||
86 | {general.competitionType} |
||
87 | </div> |
||
88 | |||
89 | <div className={"lineup__wrapper grid-x grid-margin-x cell large-12"}> |
||
90 | <div className={"cell large-6 lineup__wrapper--home"}> |
||
91 | <h3>{general.homeClub.name}</h3> |
||
92 | {this.renderLineup(lineup.home, substitutes.home)} |
||
93 | </div> |
||
94 | <div className={"cell large-6 lineup__wrapper--away"}> |
||
95 | <h3>{general.awayClub.name}</h3> |
||
96 | {this.renderLineup(lineup.away, substitutes.away)} |
||
97 | </div> |
||
98 | </div> |
||
99 | |||
100 | <div className={"cell large-12 event__wrapper"}> |
||
101 | <h3>Events</h3> |
||
102 | {this.renderEvents(events, homeTeamId)} |
||
103 | </div> |
||
104 | </div> |
||
105 | </section> |
||
106 | </Layout> |
||
107 | ) |
||
108 | } else { |
||
109 | return ( |
||
110 | <Layout> |
||
111 | <section className="grid-container site-content"> |
||
112 | Matchverslag inladen... |
||
113 | </section> |
||
114 | </Layout> |
||
115 | ) |
||
300 |